package com.yao.springcachedemo.config;

import com.yao.springcachedemo.cache.TieredCacheManager;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yao
 */
@Configuration
public class CacheConfig {
    @Bean("tieredCacheManager")
    @Primary
    public CacheManager tieredCacheManager(@Qualifier("ehCacheManager") CacheManager ehCacheManager,
                                           @Qualifier("redisCacheManager") CacheManager redisCacheManager) {
        List<CacheManager> cacheManagers = new ArrayList<>();
        cacheManagers.add(ehCacheManager);
        cacheManagers.add(redisCacheManager);
        return new TieredCacheManager(cacheManagers);
    }
}
